package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.*;
import cc.rengu.igas.momp.common.dao.impl.*;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.model.bean.JsonTmpCcbMcInfo;
import cc.rengu.igas.momp.common.util.JsonOperation;
import cc.rengu.igas.momp.facade.bean.CashierCashbackMcListInfoBean;
import cc.rengu.igas.momp.facade.request.QueryCashierCashbackMcListInfoRequest;
import cc.rengu.igas.momp.facade.response.QueryCashierCashbackMcListInfoResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.base.StringUtil;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Jinan Liu
 * @version 1.0.0
 * @date 2020/3/16 12:26
 * @description 收银员返现类活动列表查询功能实现
 */
public class QueryCashierCashbackMcListService extends RadpService {

    private String globalInstId;
    private String globalQueryType;
    private String globalQueryRole;
    private String globalQueryOrgId;
    /**
     * 操作人
     */
    private String globalQueryId;
    /**
     * 当前系统日期
     */
    private String globalTimeStamp;
    private List<TMMcOrgInfo> tmMcOrgInfoList = new ArrayList<>();
    /*营销活动查询开始时间*/
    private String globalStartTime;
    /*营销活动查询结束时间*/
    private String globalEndTime;

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {

            QueryCashierCashbackMcListInfoRequest queryCashierCashbackMcListInfoRequest = new QueryCashierCashbackMcListInfoRequest();
            ConvertUtil.convertOutput(queryCashierCashbackMcListInfoRequest);

            QueryCashierCashbackMcListInfoResponse queryCashierCashbackMcListInfoResponse = new QueryCashierCashbackMcListInfoResponse();
            queryCashierCashbackMcListInfoResponse.setHeader(queryCashierCashbackMcListInfoRequest.getHeader());
            BizResponse<QueryCashierCashbackMcListInfoResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(queryCashierCashbackMcListInfoResponse);

            //报文检查
            messageValidation(queryCashierCashbackMcListInfoRequest);
            String timeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());
            String oprId = queryCashierCashbackMcListInfoRequest.getQueryId();
            rglog.info("机构<{}>在<{}>由<{}>开始查询收银员返现类活动列表信息流程", globalInstId, timeStamp, oprId);


            /* 检查操作员所属机构号 */
            if (StringUtil.isNullorEmpty(globalQueryOrgId)) {
                rglog.error("法人机构号<{}>的操作员<{}>的所属机构为空!", globalInstId, oprId);
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            //查询上送机构及下属机构
            McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
            tmMcOrgInfoList = mcOrgInfoMapper.selectAllMcOrgInfoListByinstIdOrgId(queryCashierCashbackMcListInfoRequest.getHeader().getInstId(), globalQueryOrgId);
            if (null == tmMcOrgInfoList || tmMcOrgInfoList.size() == 0) {
                /* 代理商、收银员或用户 */
                rglog.error("查询当前角色<{}>机构<{}>及其下属机构失败!", queryCashierCashbackMcListInfoRequest.getQueryRole(), globalQueryOrgId);
                throw new BizException(RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespDesc());
            }
            // 服务调用
            BizResponse<QueryCashierCashbackMcListInfoResponse> bizResponseNew = queryCashierCashbackMcListInfo(xmlTreeUtil, queryCashierCashbackMcListInfoRequest, queryCashierCashbackMcListInfoResponse);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e));
            }
        }

        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * @param queryCashierCashbackMcListInfoRequest
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/3/17 00:28
     * @description 查询收银员返现类营销活动列表信息
     * @return: void
     */
    private BizResponse<QueryCashierCashbackMcListInfoResponse> queryCashierCashbackMcListInfo(XmlTreeUtil xmlTreeUtil, QueryCashierCashbackMcListInfoRequest queryCashierCashbackMcListInfoRequest, QueryCashierCashbackMcListInfoResponse queryCashierCashbackMcListInfoResponse)
            throws Exception {

        BizResponse<QueryCashierCashbackMcListInfoResponse> bizResponse = new BizResponse<>();
        List<CashierCashbackMcListInfoBean> cashierCashbackMcListInfoBean;

        List<CcbMcListInfoOutObj> ccbMcListInfoOutObjList = new ArrayList<>();
        PageResult pageResult;

        /* 数据库入参赋值 */
        CcbMcListInfoInObj ccbMcListInfoInObj = setupDatabaseInputObject(queryCashierCashbackMcListInfoRequest);

        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageIndex(Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageIndex()));
        pageInfo.setPageSize(Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize()));

        List<CashierCashbackMcListInfoBean> CashierCashbackMcListInfoBeanList;
        rglog.debug("当前是<{}>查询数据", QueryRoleEnum.getByValue(globalQueryRole).getQueryRoleDesc());
        if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(globalQueryType) && QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
            //银行审批岗因为数据查询的为业务数据临时表所以单独处理
            CashierCashbackMcListInfoBeanList = processTmpApsMcListInfo(queryCashierCashbackMcListInfoRequest);

            if (null == CashierCashbackMcListInfoBeanList || CashierCashbackMcListInfoBeanList.isEmpty()) {
                rglog.info("根据查询条件查询到0条收银员返现类营销活动信息!");
                queryCashierCashbackMcListInfoResponse.setTotalPage(CommonConstant.ZERO_COMMON_CONSTANT);
                queryCashierCashbackMcListInfoResponse.setTotalRows(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                queryCashierCashbackMcListInfoResponse.setTotalRows(String.valueOf(CashierCashbackMcListInfoBeanList.size()));
                if (CommonConstant.ZERO == (CashierCashbackMcListInfoBeanList.size() % Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize()))) {
                    queryCashierCashbackMcListInfoResponse.setTotalPage(String.valueOf(CashierCashbackMcListInfoBeanList.size() / Math.abs(Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize()))));
                } else {
                    queryCashierCashbackMcListInfoResponse.setTotalPage(String.valueOf(CashierCashbackMcListInfoBeanList.size() / Math.abs(Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize())) + 1));
                }
                /* 分页查询 */
                int fromIndex = Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageIndex()) * Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize());
                int endIndex = fromIndex + Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize());
                if (fromIndex <= CashierCashbackMcListInfoBeanList.size()) {
                    List<CashierCashbackMcListInfoBean> cashierCashbackMcListInfoBeanList1 = CashierCashbackMcListInfoBeanList.subList(fromIndex, Math.min(endIndex, CashierCashbackMcListInfoBeanList.size()));
                    queryCashierCashbackMcListInfoResponse.setMcListInfo(cashierCashbackMcListInfoBeanList1);
                }
            }
        } else {
            /* 根据角色权限查询数据 */
            switch (QueryTypeEnum.getByValue(globalQueryType)) {
                case BANK_QUERY_TYPE:
                    /* 银行人员,需要拼接营销活动机构信息表查询 */

                    /* 机构编号 */
                    if (!StringUtil.isNullorEmpty(globalQueryOrgId)) {
                        ccbMcListInfoInObj.setOrgId(globalQueryOrgId);
                        rglog.info("ORG_ID=<{}>", globalQueryOrgId);
                    }

                    /* 临时表数据字段1模糊查询字符串拼接 */
                    if (QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
                        String bizData = "{\"inst_id\":\"" + globalInstId + "\"%";
                        ccbMcListInfoInObj.setBizData1(bizData);
                    }

                    pageResult = queryCashierCashbackMcListInfoByBank(ccbMcListInfoInObj, pageInfo);
                    if (null != pageResult && null != pageResult.getResult()) {
                        rglog.info("SIZE=<{}>", pageResult.getResult().size());
                    }

                    break;

                case MCHNT_QYERY_TYPE:
                    /* 商户人员,需要拼接营销活动商户信息表查询 */

                    /* 根据商户编号查询商圈编号 */
                    String mchntNo = queryCashierCashbackMcListInfoRequest.getQueryId();
                    String mchntArea = null;
                    TBMchntBaseInfo tbMchntBaseInfo = null;
                    if (!StringUtil.isNullorEmpty(mchntNo)) {
                        /* 查询商户基本信息表 */
                        tbMchntBaseInfo = selectMompMchntBaseInfoByPrimaryKey(globalInstId, mchntNo);
                        if (null == tbMchntBaseInfo) {
                            rglog.error("查询法人机构<{}>商户<{}>基本信息失败!", globalInstId, mchntNo);
                            throw new BizException(RespCodeEnum.NO_TRANS_RECORD.getRespCode(), RespCodeEnum.NO_TRANS_RECORD.getRespDesc());
                        } else {
                            /* 商户编号 */
                            if (!StringUtil.isNullorEmpty(mchntNo)) {
                                ccbMcListInfoInObj.setMcNo(mchntNo);
                            }

                            /* 商圈编号 */
                            mchntArea = tbMchntBaseInfo.getMchntArea();
                            if (!StringUtil.isNullorEmpty(mchntArea)) {
                                ccbMcListInfoInObj.setMchntArea(mchntArea);
                            }
                        }
                    }

                    pageResult = queryCashierCashbackMcListInfoByMchnt(ccbMcListInfoInObj, pageInfo, mchntArea);
                    break;

                case CASHIER_QYERY_TYPE:
                    pageResult = queryCashierCashbackMcListInfoByCashier(ccbMcListInfoInObj, pageInfo, queryCashierCashbackMcListInfoRequest);
                    break;

                default:
                    /* 其他查询角色不支持 */
                    rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                    throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
            }

            /* 根据取出记录条数做对应处理 */
            if (null == pageResult || null == pageResult.getPageInfo() || null == pageResult.getResult() || pageResult.getResult().isEmpty()) {
                rglog.info("根据查询条件查询到0条收银员返现活动信息!");

                queryCashierCashbackMcListInfoResponse.setTotalPage(CommonConstant.ZERO_COMMON_CONSTANT);
                queryCashierCashbackMcListInfoResponse.setTotalRows(CommonConstant.ZERO_COMMON_CONSTANT);

            } else {

                for (Object object : pageResult.getResult()) {
                    ccbMcListInfoOutObjList.add((CcbMcListInfoOutObj) object);
                }

                rglog.info("SIZE=<{}>", pageResult.getResult().size());

                cashierCashbackMcListInfoBean = ccbMcListInfoOutObjList.stream().map(this::convertMcCashierCashBackInfo).collect(Collectors.toList());
                queryCashierCashbackMcListInfoResponse.setMcListInfo(cashierCashbackMcListInfoBean);
                queryCashierCashbackMcListInfoResponse.setTotalPage(Integer.toString(pageResult.getPageInfo().getTotalPage()));
                queryCashierCashbackMcListInfoResponse.setTotalRows(Integer.toString(pageResult.getPageInfo().getTotalRows()));
                List<CashierCashbackMcListInfoBean> CashierCashbackMcListInfoBeanList1 = new ArrayList<>();
                //如果上送查询条件有商户/商圈号或者商户/商圈号商圈名称
                if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMchntNo()) || !StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMchntName())) {
                    if (globalQueryType.equals(QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode())) {
                        //重新查询收银员活动信息列表（不分页）
                        McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
                        List<CcbMcListInfoOutObj> ccbMcListInfoOutObjList1 = mcInfoListMapper.selectCashierCashbackMcListInfoForBaseRole(globalInstId, globalQueryOrgId, queryCashierCashbackMcListInfoRequest.getMcType(), queryCashierCashbackMcListInfoRequest.getMcStatus(), queryCashierCashbackMcListInfoRequest.getHeader().getTransDate(), queryCashierCashbackMcListInfoRequest.getCashbackMethod());
                        //查询营销活动商户信息表
                        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
                        List<TMMcMchntInfo> tmMcMchntInfoList = mcMchntInfoMapper.selectMcMchntInfoListByinstIdMchntNo(globalInstId, queryCashierCashbackMcListInfoRequest.getMchntNo(), queryCashierCashbackMcListInfoRequest.getMchntName());
                        if (null != tmMcMchntInfoList && tmMcMchntInfoList.size() > 0) {
                            //循环判断符合条件的营销活动
                            for (TMMcMchntInfo tmMcMchntInfo : tmMcMchntInfoList) {
                                List<CashierCashbackMcListInfoBean> cashierCashbackMcListInfoBeanList2 = ccbMcListInfoOutObjList1.stream().map(this::convertMcCashierCashBackInfo).collect(Collectors.toList());
                                cashierCashbackMcListInfoBeanList2 = cashierCashbackMcListInfoBeanList2.stream().filter(item -> tmMcMchntInfo.getMcNo().equals(item.getMcNo())).collect(Collectors.toList());
                                if (null != cashierCashbackMcListInfoBeanList2 && cashierCashbackMcListInfoBeanList2.size() > 0) {
                                    CashierCashbackMcListInfoBeanList1.addAll(cashierCashbackMcListInfoBeanList2);
                                }
                            }
                            CashierCashbackMcListInfoBeanList1 = CashierCashbackMcListInfoBeanList1.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CashierCashbackMcListInfoBean::getMcNo))), ArrayList::new));

                        }
                        /* 分页查询 */
                        int fromIndex = Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageIndex()) * Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize());
                        int endIndex = fromIndex + Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize());
                        if (fromIndex <= CashierCashbackMcListInfoBeanList1.size()) {
                            List<CashierCashbackMcListInfoBean> mcListInfoBeanList1 = CashierCashbackMcListInfoBeanList1.subList(fromIndex, Math.min(endIndex, CashierCashbackMcListInfoBeanList1.size()));
                            queryCashierCashbackMcListInfoResponse.setMcListInfo(mcListInfoBeanList1);
                        }
                        if (CommonConstant.ZERO == (CashierCashbackMcListInfoBeanList1.size() % Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize()))) {
                            queryCashierCashbackMcListInfoResponse.setTotalPage(String.valueOf(CashierCashbackMcListInfoBeanList1.size() / Math.abs(Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize()))));
                        } else {
                            queryCashierCashbackMcListInfoResponse.setTotalPage(String.valueOf(CashierCashbackMcListInfoBeanList1.size() / Math.abs(Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize())) + 1));
                            queryCashierCashbackMcListInfoResponse.setTotalRows(String.valueOf(CashierCashbackMcListInfoBeanList1.size()));
                        }
                    }
                }

            }
        }
        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        queryCashierCashbackMcListInfoResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        queryCashierCashbackMcListInfoResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        queryCashierCashbackMcListInfoResponse.setPageIndex(queryCashierCashbackMcListInfoRequest.getPageIndex());
        queryCashierCashbackMcListInfoResponse.setPageSize(queryCashierCashbackMcListInfoRequest.getPageSize());

        bizResponse.setResult(queryCashierCashbackMcListInfoResponse);

        return bizResponse;

    }

    /**
     * 数据库查询前赋值数据库实体类入参
     *
     * @param queryCashierCashbackMcListInfoRequest 收银员返现营销活动列表查询接口请求对象
     * @return cc.rengu.igas.momp.common.entity.CcbMcListInfoInObj 收银员返现营销活动列表查询使用实体类入参
     * @author Jinan Liu
     * @date 2020/5/28 12:57
     */
    private CcbMcListInfoInObj setupDatabaseInputObject(QueryCashierCashbackMcListInfoRequest queryCashierCashbackMcListInfoRequest) {

        CcbMcListInfoInObj ccbMcListInfoInObj = new CcbMcListInfoInObj();

        /* 机构编码 */
        ccbMcListInfoInObj.setInstId(globalInstId);
        rglog.info("INST_ID=<{}>", globalInstId);

        /* 营销活动编号 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcNo())) {
            ccbMcListInfoInObj.setMcNo(queryCashierCashbackMcListInfoRequest.getMcNo());
        }
        /* 营销活动名称 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcName())) {
            ccbMcListInfoInObj.setMcName(queryCashierCashbackMcListInfoRequest.getMcName());
        }
        /* 营销活动类型 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcType())) {
            ccbMcListInfoInObj.setMcType(queryCashierCashbackMcListInfoRequest.getMcType());
        }
        /* 营销活动状态 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcStatus())) {
            ccbMcListInfoInObj.setMcStatus(queryCashierCashbackMcListInfoRequest.getMcStatus());
            if (queryCashierCashbackMcListInfoRequest.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                ccbMcListInfoInObj.setRemark1(McStatusEnum.ALL_ENDED.getMcStatusCode());
            }
        }
        /* 审批状态 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getAuditStatus())) {
            ccbMcListInfoInObj.setAuditStatus(queryCashierCashbackMcListInfoRequest.getAuditStatus());
        }
        /* 营销方式 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getCashbackMethod())) {
            ccbMcListInfoInObj.setCashbackMethod(queryCashierCashbackMcListInfoRequest.getCashbackMethod());
        }
        /* 当前系统日期 */
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getHeader().getTransDate())) {
            ccbMcListInfoInObj.setTxnDate(queryCashierCashbackMcListInfoRequest.getHeader().getTransDate());
            rglog.info("TXN_DATE=<{}>", queryCashierCashbackMcListInfoRequest.getHeader().getTransDate());
        }
        if (!StringUtil.isNullorEmpty(globalStartTime)) {
            ccbMcListInfoInObj.setStartTime(globalStartTime);
        }
        if (!StringUtil.isNullorEmpty(globalEndTime)) {
            ccbMcListInfoInObj.setEndTime(globalEndTime);
        }
        return ccbMcListInfoInObj;
    }

    /**
     * 银行人员查询数据
     *
     * @param ccbMcListInfoInObj 收银员返现营销活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/27 23:14
     */
    private PageResult queryCashierCashbackMcListInfoByBank(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo) throws Exception {

        switch (QueryRoleEnum.getByValue(globalQueryRole)) {
            case BANK_BASIC_QUERY_ROLE:
                /* 银行录入岗 */
                return selectCcbMcListInfoByBankBasicRole(ccbMcListInfoInObj, pageInfo);
            case BANK_PUBLISH_QYERY_ROLE:
                /* 银行发布岗 */
                return selectCcbMcListInfoByBankPublishRole(ccbMcListInfoInObj, pageInfo);
            default:
                /* 其他查询角色不支持 */
                rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
        }
    }

    /**
     * 银行操作员查询收银员返现活动列表数据库操作
     *
     * @param ccbMcListInfoInObj 收银员返现营销活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 00:47
     */
    private PageResult selectCcbMcListInfoByBankBasicRole(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo) throws Exception {

        McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
        return mcInfoListMapper.selectCcbMcListInfoByBankBasicRole(ccbMcListInfoInObj, pageInfo);
    }

    /**
     * 银行发布员查询收银员返现活动列表数据库操作
     *
     * @param ccbMcListInfoInObj 收银员返现活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 01:13
     */
    private PageResult selectCcbMcListInfoByBankPublishRole(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo) throws Exception {

        McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
        return mcInfoListMapper.selectCcbMcListInfoByBankPublishRole(ccbMcListInfoInObj, pageInfo);
    }

    /**
     * 使用商户编号从内管商户基本信息表查询商户所属商圈编号
     *
     * @param instId  法人机构号
     * @param mchntNo 商户编号
     * @return cc.rengu.igas.momp.common.entity.TBMchntBaseInfo 商户基本信息表T_B_MCHNT_BASE_INFO
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 13:06
     * @version 1.0.0
     */
    private TBMchntBaseInfo selectMompMchntBaseInfoByPrimaryKey(String instId, String mchntNo) throws Exception {

        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
        return mchntInfoMapper.selectMompMchntBaseInfoByPrimaryKey(instId, mchntNo);
    }

    /**
     * 商户查询数据
     *
     * @param ccbMcListInfoInObj 收银员返现活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @param mchntArea          商圈编号
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 13:15
     */
    private PageResult queryCashierCashbackMcListInfoByMchnt(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo, String mchntArea) throws Exception {

        switch (QueryRoleEnum.getByValue(globalQueryRole)) {
            case MCHNT_QYERY_ROLE:
                /* 商户 */
                return selectCashierCashBackMcListInfoByMchnt(ccbMcListInfoInObj, pageInfo, mchntArea);
            default:
                /* 其他查询角色不支持 */
                rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
        }
    }

    /**
     * 商户查询数据
     *
     * @param ccbMcListInfoInObj 收银员返现活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @param mchntArea          商圈编号
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 13:13
     */
    private PageResult selectCashierCashBackMcListInfoByMchnt(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo, String mchntArea) throws Exception {

        McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
        if (StringUtil.isNullorEmpty(mchntArea)) {
            return mcInfoListMapper.selectCcbMcListInfoByMchnt(ccbMcListInfoInObj, pageInfo);
        } else {
            return mcInfoListMapper.selectCcbMcListInfoByMchntWithArea(ccbMcListInfoInObj, pageInfo);
        }
    }

    /**
     * 数据库实体类和接口实体类数据转换
     *
     * @param ccbMcListInfoOutObj 收银员活动列表查询使用实体类出参
     * @return cc.rengu.igas.momp.facade.bean.CashierCashbackMcListInfoBean 收银员活动列表查询接口应答对象
     * @author Jinan Liu
     * @date 2020/5/28 00:15
     */
    private CashierCashbackMcListInfoBean convertMcCashierCashBackInfo(CcbMcListInfoOutObj ccbMcListInfoOutObj) {

        CashierCashbackMcListInfoBean cashierCashbackMcListInfoBean = new CashierCashbackMcListInfoBean();
        try {
            /* 营销活动编号 */
            cashierCashbackMcListInfoBean.setMcNo(ccbMcListInfoOutObj.getMcNo());
            /* 营销活动名称 */
            cashierCashbackMcListInfoBean.setMcName(ccbMcListInfoOutObj.getMcName());
            /* 营销活动类型 */
            cashierCashbackMcListInfoBean.setMcType(ccbMcListInfoOutObj.getMcType());
            /* 营销活动状态 */
            cashierCashbackMcListInfoBean.setMcStatus(ccbMcListInfoOutObj.getMcStatus());
            /* 营销活动方式 */
            cashierCashbackMcListInfoBean.setCashbackMethod(ccbMcListInfoOutObj.getCashbackMethod());
            /* 活动起始日期 */
            cashierCashbackMcListInfoBean.setMcStartDate(ccbMcListInfoOutObj.getMcStartDate());
            /* 活动截止日期 */
            cashierCashbackMcListInfoBean.setMcEndDate(ccbMcListInfoOutObj.getMcEndDate());
            /* 活动结束日期 */
            cashierCashbackMcListInfoBean.setMcActualEndDate(ccbMcListInfoOutObj.getMcActualEndDate());
            /* 活动预算 */
            cashierCashbackMcListInfoBean.setBudget(ccbMcListInfoOutObj.getBudget());
            /* 已消耗预算 */
            if (StringUtil.isNullorEmpty(ccbMcListInfoOutObj.getTotalAmtAcc())) {
                cashierCashbackMcListInfoBean.setBudgetUsed(CommonConstant.ZERO_AMOUNT);
            } else {
                cashierCashbackMcListInfoBean.setBudgetUsed(ccbMcListInfoOutObj.getTotalAmtAcc());
            }
            /* 审批状态 */
            cashierCashbackMcListInfoBean.setAuditStatus(ccbMcListInfoOutObj.getAuditStatus());
            /* 创建人 */
            cashierCashbackMcListInfoBean.setOprId(ccbMcListInfoOutObj.getOprId());
            /* 创建时间 */
            cashierCashbackMcListInfoBean.setCreateTime(ccbMcListInfoOutObj.getCreateTime());
            /* 最后修改人 */
            if (StringUtil.isNullorEmpty(ccbMcListInfoOutObj.getLastOprId())) {
                cashierCashbackMcListInfoBean.setLastOprId("");
            } else {
                cashierCashbackMcListInfoBean.setLastOprId(ccbMcListInfoOutObj.getLastOprId());
            }
            /* 修改时间 */
            if (StringUtil.isNullorEmpty(ccbMcListInfoOutObj.getUpdateTime())) {
                cashierCashbackMcListInfoBean.setUpdateTime("");
            } else {
                cashierCashbackMcListInfoBean.setUpdateTime(ccbMcListInfoOutObj.getUpdateTime());
            }
            if (globalQueryType.equals(QueryTypeEnum.CASHIER_QYERY_TYPE.getQueryTypeCode())) {
                /* 查询主体参加活动标志_收银员是否已加入营销活动 */
                cashierCashbackMcListInfoBean.setAttendFlag(ccbMcListInfoOutObj.getAttendFlag());
                rglog.info("收银员查询时，收银员参与活动标志<{}>", ccbMcListInfoOutObj.getAttendFlag());
            } else {
                //判断上送机构及其下属机构是否包含活动原创建机构
                List<TMMcOrgInfo> newList = tmMcOrgInfoList.stream().filter(item -> item.getOrgId().equals(ccbMcListInfoOutObj.getCrtOrgId())).collect(Collectors.toList());
                if (null != newList && newList.size() > 0) {
                    /* 已参与营销活动 */
                    cashierCashbackMcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                } else {
                    /* 未参与营销活动 */
                    cashierCashbackMcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_NO);
                }
            }
        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换营销活动信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return cashierCashbackMcListInfoBean;
    }

    /**
     * 银行审批岗数据查询
     *
     * @param queryCashierCashbackMcListInfoRequest 收银员返现活动列表查询接口请求对象
     * @return java.util.List<cc.rengu.igas.momp.facade.bean.CashierCashbackMcListInfoBean> 收银员返现类营销活动列表查询接口应答对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/6/20 16:53
     */
    private List<CashierCashbackMcListInfoBean> processTmpApsMcListInfo(QueryCashierCashbackMcListInfoRequest queryCashierCashbackMcListInfoRequest) throws Exception {

        List<CashierCashbackMcListInfoBean> cashierCashbackMcListInfoBeanList;

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
        tmPlatBizTmp.setInstId(globalInstId);
        tmPlatBizTmp.setOrgId(globalQueryOrgId);
        tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode());

        //营销活动编号
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcNo())) {
            tmPlatBizTmp.setMcNo(queryCashierCashbackMcListInfoRequest.getMcNo());
        }
        //营销活动状态
        if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcStatus())) {
            tmPlatBizTmp.setMcStatus(queryCashierCashbackMcListInfoRequest.getMcStatus());
        }

        // 查询临时表获取数据
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        List<TMPlatBizTmp> tmPlatBizTmpList = platBizTmpMapper.selectTmpMcListInfo(tmPlatBizTmp);
        if (null != tmPlatBizTmpList && !tmPlatBizTmpList.isEmpty()) {
            cashierCashbackMcListInfoBeanList = tmPlatBizTmpList.stream().map(this::convertTmpMcInfo).collect(Collectors.toList());
            rglog.debug("活动查询结果 SIZE=<{}>", cashierCashbackMcListInfoBeanList.size());

            /* 代码过滤查询条件 */
            //按照营销活动名称筛选
            if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcName())) {
                cashierCashbackMcListInfoBeanList = cashierCashbackMcListInfoBeanList.stream().filter(item -> item.getMcName().contains(queryCashierCashbackMcListInfoRequest.getMcName())).collect(Collectors.toList());
            }
            //按照营销活动类型筛选
            if (!StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMcType())) {
                cashierCashbackMcListInfoBeanList = cashierCashbackMcListInfoBeanList.stream().filter(item -> item.getMcType().equals(queryCashierCashbackMcListInfoRequest.getMcType())).collect(Collectors.toList());
            }
            return cashierCashbackMcListInfoBeanList;
        } else {
            return null;
        }
    }

    /**
     * 转换换业务数据临时表临时数据
     *
     * @param tmPlatBizTmp 业务数据临时表
     * @return cc.rengu.igas.momp.facade.bean.CashierCashbackMcListInfoBean 收银员返现类营销活动列表查询接口应答对象
     * @author Jinan Liu
     * @date 2020/6/20 15:37
     */
    private CashierCashbackMcListInfoBean convertTmpMcInfo(TMPlatBizTmp tmPlatBizTmp) {

        CashierCashbackMcListInfoBean cashierCashbackMcListInfoBean = new CashierCashbackMcListInfoBean();
        try {
            String mcNo;
            String mcName;
            String mcType;
            String mcStartDate;
            String mcEndDate;
            String mcActualEndDate;
            String budget;
            String mcStatus;
            String cashbackMethod;
            /* 根据营销活动类型解析BIZ_DATA1字段内容 */
            String mcTypeOne = tmPlatBizTmp.getMcNo().substring(2, 3);
            if (McTypeEnum.MC_TYPE_CCB.getMcTypeCode().equals(mcTypeOne)) {
                JsonTmpCcbMcInfo jsonTmpCcbMcInfo = (JsonTmpCcbMcInfo) JsonOperation.parseMcInfoTmpBizData1(rglog, tmPlatBizTmp, TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode());
                mcNo = jsonTmpCcbMcInfo.getMcNo();
                mcName = jsonTmpCcbMcInfo.getMcName();
                mcType = jsonTmpCcbMcInfo.getMcType();
                mcStartDate = jsonTmpCcbMcInfo.getMcStartDate();
                mcEndDate = jsonTmpCcbMcInfo.getMcEndDate();
                mcActualEndDate = jsonTmpCcbMcInfo.getMcActualEndDate();
                budget = jsonTmpCcbMcInfo.getBudget();
                mcStatus = jsonTmpCcbMcInfo.getMcStatus();
                cashbackMethod = jsonTmpCcbMcInfo.getCashbackMethod();
            } else {
                rglog.error("不支持的营销活动类型<{}>,不可转换数据!", mcTypeOne);
                throw new BizException(RespCodeEnum.NOT_SUPPORTED_MC_TYPE_ERROR.getRespCode(), RespCodeEnum.NOT_SUPPORTED_MC_TYPE_ERROR.getRespDesc());
            }

            /* 营销活动编号 */
            cashierCashbackMcListInfoBean.setMcNo(mcNo);
            /* 营销活动名称 */
            cashierCashbackMcListInfoBean.setMcName(mcName);
            /* 营销活动类型 */
            cashierCashbackMcListInfoBean.setMcType(mcType);
            /* 活动起始日期 */
            cashierCashbackMcListInfoBean.setMcStartDate(mcStartDate);
            /* 活动截止日期 */
            cashierCashbackMcListInfoBean.setMcEndDate(mcEndDate);
            /* 活动结束日期 */
            cashierCashbackMcListInfoBean.setMcActualEndDate(mcActualEndDate);
            /* 活动预算 */
            cashierCashbackMcListInfoBean.setBudget(budget);
            /* 已消耗预算 */
            cashierCashbackMcListInfoBean.setBudgetUsed(CommonConstant.ZERO_AMOUNT);
            /* 审批状态 */
            cashierCashbackMcListInfoBean.setAuditStatus(tmPlatBizTmp.getAuditStatus());
            /* 创建人 */
            cashierCashbackMcListInfoBean.setOprId(tmPlatBizTmp.getOprId());
            /* 创建时间 */
            cashierCashbackMcListInfoBean.setCreateTime(tmPlatBizTmp.getCreateTime());
            /* 最后修改人 */
            cashierCashbackMcListInfoBean.setLastOprId(tmPlatBizTmp.getLastOprId());
            /* 修改时间 */
            cashierCashbackMcListInfoBean.setUpdateTime(tmPlatBizTmp.getLastUpdateTime());
            /* 营销活动状态 */
            cashierCashbackMcListInfoBean.setMcStatus(mcStatus);
            /* 营销活动方式 */
            cashierCashbackMcListInfoBean.setCashbackMethod(cashbackMethod);

        } catch (Exception e) {
            rglog.error("转换营销活动临时表信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return cashierCashbackMcListInfoBean;
    }

    /**
     * 请求报文体内容检查
     *
     * @param queryCashierCashbackMcListInfoRequest 收银员返现类活动列表查询接口请求对象
     * @author Jinan Liu
     * @date 2020/6/20 09:55
     */
    private void messageValidation(QueryCashierCashbackMcListInfoRequest queryCashierCashbackMcListInfoRequest) {

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getHeader().getTransDate())) {
            rglog.error("交易日期必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getHeader().getTransTime())) {
            rglog.error("交易时间必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getHeader().getInstId())) {
            rglog.error("法人机构号必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalInstId = queryCashierCashbackMcListInfoRequest.getHeader().getInstId();
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getHeader().getTraceNo())) {
            rglog.error("流水号必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getQueryType())) {
            rglog.error("操作员类型为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryType = queryCashierCashbackMcListInfoRequest.getQueryType();
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getQueryId())) {
            rglog.error("操作员ID为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryId = queryCashierCashbackMcListInfoRequest.getQueryId();
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getQueryRole())) {
            rglog.error("操作员角色为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryRole = queryCashierCashbackMcListInfoRequest.getQueryRole();
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getQueryOrgId())) {
            rglog.error("操作员所属法人机构为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryOrgId = queryCashierCashbackMcListInfoRequest.getQueryOrgId();
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getPageIndex())) {
            rglog.error("当前页数为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            int pageIndex = Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageIndex());
            if (CommonConstant.ZERO > pageIndex) {
                rglog.error("当前查询页数必须大于0! PAGE_INDEX=<{}>", pageIndex);
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
        }

        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getPageSize())) {
            rglog.error("页显示记录数为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            int pageSize = Integer.parseInt(queryCashierCashbackMcListInfoRequest.getPageSize());
            if (CommonConstant.ONE > pageSize) {
                rglog.error("每页记录数必须大于等于1! PAGE_SIZE=<{}>", pageSize);
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
        }
        globalTimeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());
        globalStartTime = queryCashierCashbackMcListInfoRequest.getStartTime();
        globalEndTime = queryCashierCashbackMcListInfoRequest.getEndTime();
    }

    /**
     * 收银员查询数据
     *
     * @param ccbMcListInfoInObj 收银员返现活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/10 16:15
     */
    private PageResult queryCashierCashbackMcListInfoByCashier(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo, QueryCashierCashbackMcListInfoRequest queryCashierCashbackMcListInfoRequest) throws Exception {

        //接口上送的收银员用户号0
        String userId = queryCashierCashbackMcListInfoRequest.getQueryId();

        rglog.error("查询收银员<{}>的所属商户信息!", userId);
        if (StringUtil.isNullorEmpty(queryCashierCashbackMcListInfoRequest.getMchntNo())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",收银员查询，未上送商户号");
        }
        String mchntNo = queryCashierCashbackMcListInfoRequest.getMchntNo();
        String mchntArea = null;
        TBMchntBaseInfo tbMchntBaseInfo = null;
        if (!StringUtil.isNullorEmpty(mchntNo)) {
            //查询商户基本信息表
            tbMchntBaseInfo = selectMompMchntBaseInfoByPrimaryKey(globalInstId, mchntNo);
            if (null == tbMchntBaseInfo) {
                rglog.error("查询法人机构<{}>商户<{}>基本信息失败!", globalInstId, mchntNo);
                throw new BizException(RespCodeEnum.NO_TRANS_RECORD.getRespCode(), RespCodeEnum.NO_TRANS_RECORD.getRespDesc());
            } else {
                //商户编号
                if (!StringUtil.isNullorEmpty(mchntNo)) {
                    ccbMcListInfoInObj.setMchntNo(mchntNo);
                }
                //商圈编号
                mchntArea = tbMchntBaseInfo.getMchntArea();
                if (!StringUtil.isNullorEmpty(mchntArea)) {
                    ccbMcListInfoInObj.setMchntArea(mchntArea);
                }
            }
        }

        switch (QueryRoleEnum.getByValue(globalQueryRole)) {
            case CASHIER_QYERY_ROLE:
                //收银员
                return selectCashierCashBackMcListInfoByCashier(ccbMcListInfoInObj, pageInfo, mchntArea, userId);
            default:
                //其他查询角色不支持
                rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
        }
    }

    /**
     * 收银员查询数据
     *
     * @param ccbMcListInfoInObj 收银员返现活动列表查询使用实体类入参
     * @param pageInfo           数据库操作分页请求实体类
     * @param mchntArea          商圈编号
     * @return cc.rengu.oltp.utility.bean.PageResult 数据库操作分页应答实体类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/10 16:15
     */
    private PageResult selectCashierCashBackMcListInfoByCashier(CcbMcListInfoInObj ccbMcListInfoInObj, PageInfo pageInfo, String mchntArea, String userId) throws Exception {

        PageResult pageResult = null;

        McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
        if (StringUtil.isNullorEmpty(mchntArea)) {
            pageResult = mcInfoListMapper.selectCcbMcListInfoByMchnt(ccbMcListInfoInObj, pageInfo);
        } else {
            pageResult = mcInfoListMapper.selectCcbMcListInfoByMchntWithArea(ccbMcListInfoInObj, pageInfo);
        }

        //查询到的结果不为空
        if (null != pageResult && null != pageResult.getPageInfo() && null != pageResult.getResult() && !pageResult.getResult().isEmpty()) {
            rglog.info("对查询到的营销活动信息进一步处理，判断收银员是否已参加...");
            McAccountInfoMapper mcAccountInfoMapper = new McAccountInfoMapperImpl();

            PageResult returnPageResult = new PageResult();
            returnPageResult.setPageInfo(pageResult.getPageInfo());

            List<Object> result = new ArrayList<>();
            for (Object object : pageResult.getResult()) {
                String mcNo = ((CcbMcListInfoOutObj) object).getMcNo();
                //查询营销活动用户信息表
                /**判断是否存在营销活动用户信息表*/
                TMMcUserInfo tmMcUserInfo = mcAccountInfoMapper.selcetMcMchntInfoByInstIdMcNoAcctNo(globalInstId, mcNo, userId);
                if (null != tmMcUserInfo) {
                    rglog.info("根据法人机构号<{}>营销活动编号<{}>用户号<{}>查询营销活动用户信息表信息已存在,收银员已加入营销活动", globalInstId, mcNo, userId);
                    ((CcbMcListInfoOutObj) object).setAttendFlag(CommonConstant.TWO_COMMON_CONSTANT);
                } else {
                    rglog.info("根据法人机构号<{}>营销活动编号<{}>用户号<{}>未查询营销活动用户信息表数据,收银员未加入营销活动", globalInstId, mcNo, userId);
                    ((CcbMcListInfoOutObj) object).setAttendFlag(CommonConstant.ONE_COMMON_CONSTANT);
                }
                result.add(object);
                rglog.info("收银员活动参与标志<{}>", ((CcbMcListInfoOutObj) object).getAttendFlag());
            }
            returnPageResult.setResult(result);

            return returnPageResult;
        }

        return pageResult;
    }

}
